<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(name, typed) {
      let i = 0;
      let j = 0;

      while (i < name.length || j < typed.length) {
        if (name[i] === typed[j]) {
          i++;
          j++;
        } else if (name[i] !== typed[j] && i > 0 && name[i - 1] === typed[j]) {
          j++;
        } else {
          return false;
        }
      }
      return true;
    };
    console.log(arr(name = "alex", typed = "aaleex"));
  </script>
</body>

</html>